package luj.tool.jnproxyan.proxy.network.socks.actor.root.message.request.disconnect;

import luj.tool.jnproxyan.proxy.network.socks.actor.root.Socks5Actor;
import luj.tool.jnproxyan.proxy.network.socks.request.op.SocksReqGetter;
import luj.tool.jnproxyan.proxy.network.socks.request.SocksRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
final class OnP2sDisconnect implements Socks5Actor.Handler<P2sDisconnectMsg> {

  @Override
  public void onHandle(Context ctx) throws Exception {
    Socks5Actor self = ctx.getActorState(this);
    P2sDisconnectMsg msg = ctx.getMessage(this);

    Long reqId = msg.reqId();
    SocksRequest req = _reqGetter.inject(self, reqId).getReq();//.remove(reqId);

    req.getC2pConnV2().close();
    req.getWebReqQueue().clear();
  }

  @Autowired
  SocksReqGetter _reqGetter;
}
